home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Development Environments ƒ / Perl 4.0.2 ƒ / unix / installperl < prev    next >
Encoding:
Text File  |  1992-01-05  |  4.8 KB  |  206 lines

  1. #!./perl
  2.  
  3. while (@ARGV) {
  4.     $nonono = 1 if $ARGV[0] eq '-n';
  5.     $versiononly = 1 if $ARGV[0] eq '-v';
  6.     shift;
  7. }
  8.  
  9. umask 022;
  10.  
  11. @scripts = ('cppstdin', 'h2ph', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
  12. @manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
  13.  
  14. $version = sprintf("%5.3f", $]);
  15. $release = substr($version,0,3);
  16. $patchlevel = substr($version,3,2);
  17.  
  18. # Read in the config file.
  19.  
  20. open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
  21. while (<CONFIG>) {
  22.     if (s/^(\w+=)/\$$1/) {
  23.     $accum =~ s/'undef'/undef/g;
  24.     eval $accum;
  25.     $accum = '';
  26.     }
  27.     $accum .= $_;
  28. }
  29.  
  30. # Do some quick sanity checks.
  31.  
  32. if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
  33.  
  34.    $installbin        || die "No installbin directory in config.sh\n";
  35. -d $installbin        || die "$installbin is not a directory\n";
  36. -w $installbin        || die "$installbin is not writable by you\n"
  37.     unless $installbin =~ m#^/afs/#;
  38.  
  39. -x 'perl'        || die "perl isn't executable!\n";
  40. -x 'taintperl'        || die "taintperl isn't executable!\n";
  41. -x 'suidperl'        || die "suidperl isn't executable!\n" if $d_dosuid;
  42.  
  43. -x 't/TEST'        || warn "WARNING: You've never run 'make test'!!!",
  44.     "  (Installing anyway.)\n";
  45.  
  46. # First we install the version-numbered executables.
  47.  
  48. $ver = sprintf("%5.3f", $]);
  49.  
  50. &unlink("$installbin/perl$ver");
  51. &cmd("cp perl $installbin/perl$ver");
  52.  
  53. &unlink("$installbin/tperl$ver");
  54. &cmd("cp taintperl $installbin/tperl$ver");
  55. &chmod(0755, "$installbin/tperl$ver");        # force non-suid for security
  56.  
  57. &unlink("$installbin/sperl$ver");
  58. if ($d_dosuid) {
  59.     &cmd("cp suidperl $installbin/sperl$ver");
  60.     &chmod(04711, "$installbin/sperl$ver");
  61. }
  62.  
  63. exit 0 if $versiononly;
  64.  
  65. # Make links to ordinary names if installbin directory isn't current directory.
  66.  
  67. ($bdev,$bino) = stat($installbin);
  68. ($ddev,$dino) = stat('.');
  69.  
  70. if ($bdev != $ddev || $bino != $dino) {
  71.     &unlink("$installbin/perl", "$installbin/taintperl", "$installbin/suidperl");
  72.     &link("$installbin/perl$ver", "$installbin/perl");
  73.     &link("$installbin/tperl$ver", "$installbin/taintperl");
  74.     &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
  75. }
  76.  
  77. ($bdev,$bino) = stat($installbin);
  78. ($ddev,$dino) = stat('x2p');
  79.  
  80. if ($bdev != $ddev || $bino != $dino) {
  81.     &unlink("$installbin/a2p");
  82.     &cmd("cp x2p/a2p $installbin/a2p");
  83. }
  84.  
  85. # Make some enemies in the name of standardization.   :-)
  86.  
  87. ($udev,$uino) = stat("/usr/bin");
  88.  
  89. if (-w _ && ($udev != $ddev || $uino != $dino) && !$nonono) {
  90.     &unlink("/usr/bin/perl");
  91.     eval 'symlink("$installbin/perl", "/usr/bin/perl")' ||
  92.     eval 'link("$installbin/perl", "/usr/bin/perl")' ||
  93.     &cmd("cp $installbin/perl /usr/bin");
  94. }
  95.  
  96. # Install scripts.
  97.  
  98. &makedir($installscr);
  99.  
  100. for (@scripts) {
  101.     &cmd("cp $_ $installscr");
  102.     s#.*/##; &chmod(0755, "$installscr/$_");
  103. }
  104.  
  105. # Install man pages.
  106.  
  107. if ($mansrc ne '') {
  108.     &makedir($mansrc);
  109.  
  110.     ($mdev,$mino) = stat($mansrc);
  111.     if ($mdev != $ddev || $mino != $dino) {
  112.     for (@manpages) {
  113.         ($new = $_) =~ s/man$/$manext/;
  114.         $new =~ s#.*/##;
  115.         print STDERR "  Installing $mansrc/$new\n";
  116.         next if $nonono;
  117.         open(MI,$_);
  118.         open(MO,">$mansrc/$new");
  119.         print MO ".ds RP Release $release Patchlevel $patchlevel\n";
  120.         while (<MI>) {
  121.         print MO;
  122.         }
  123.         close MI;
  124.         close MO;
  125.     }
  126.     }
  127. }
  128.  
  129. # Install library files.
  130.  
  131. &makedir($installprivlib);
  132. if (chdir "lib") {
  133.  
  134.     ($pdev,$pino) = stat($installprivlib);
  135.     ($ldev,$lino) = stat('.');
  136.  
  137.     if ($pdev != $ldev || $pino != $lino) {
  138.     foreach $file (<*.pl>) {
  139.         system "cmp", "-s", $file, "$privlib/$file";
  140.         if ($?) {
  141.         &unlink("$installprivlib/$file");
  142.         &cmd("cp $file $installprivlib");
  143.         }
  144.     }
  145.     }
  146.     chdir ".." || die "Can't cd back to source directory: $!\n";
  147. }
  148. else {
  149.     warn "Can't cd to lib to install lib files: $!\n";
  150. }
  151.  
  152. &chmod(0755, "usub/mus");
  153.  
  154. print STDERR "  Installation complete\n";
  155.  
  156. exit 0;
  157.  
  158. ###############################################################################
  159.  
  160. sub unlink {
  161.     local(@names) = @_;
  162.  
  163.     foreach $name (@names) {
  164.     next unless -e $name;
  165.     print STDERR "  unlink $name\n";
  166.     unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
  167.     }
  168. }
  169.  
  170. sub cmd {
  171.     local($cmd) = @_;
  172.     print STDERR "  $cmd\n";
  173.     unless ($nonono) {
  174.     system $cmd;
  175.     warn "Command failed!!!\n" if $?;
  176.     }
  177. }
  178.  
  179. sub link {
  180.     local($from,$to) = @_;
  181.  
  182.     print STDERR "  ln $from $to\n";
  183.     link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
  184. }
  185.  
  186. sub chmod {
  187.     local($mode,$name) = @_;
  188.  
  189.     printf STDERR "  chmod %o %s\n", $mode, $name;
  190.     chmod($mode,$name) || warn "Couldn't chmod $mode $name: $!\n"
  191.     unless $nonono;
  192. }
  193.  
  194. sub makedir {
  195.     local($dir) = @_;
  196.     unless (-d $dir) {
  197.     local($shortdir) = $dir;
  198.  
  199.     $shortdir =~ s#(.*)/.*#$1#;
  200.     &makedir($shortdir);
  201.  
  202.     print STDERR "  mkdir $dir\n";
  203.     mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
  204.     }
  205. }
  206.